package com.halixun.d2app.dialog;


import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.halixun.d2app.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class LoadingFragment extends DialogFragment {

    public static final String KEY_TITLE = LoadingFragment.class.getSimpleName()+"key_title";

    public static LoadingFragment getInstance(String title){
        LoadingFragment loadingFragment = new LoadingFragment();
        Bundle params = new Bundle();
        params.putString(KEY_TITLE,title);
        loadingFragment.setArguments(params);
        return loadingFragment;
    }

    private String title;

    private TextView mMessage;

    public LoadingFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        title = getArguments().getString(KEY_TITLE);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_loading, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
        setTextMessage();
    }

    private void initView(View view) {
        mMessage = view.findViewById(R.id.mMessage);
    }

    public void setTextMessage(String message){
        this.title = message;
        setTextMessage();
    }

    public void setTextMessage(){
        mMessage.setText(title);
    }
}
